<?php
namespace Common\Controller;
use Base\Controller;
use User\Event\UserEvent;

class PublicController extends Controller {
	//网站相关配置
	var $config=array();
	//当前用户
	var $user=array();
	var $user_id;
	// 分页展示数
	protected $limit = 20;
	//缓存时间 s
	protected $cacheTime = 120;
	//登录信息
	protected $loginInfo;
	//内容类型
	protected $contentType = array(
		'idea'  =>  1,  //灵感
		'ask'   =>  2,  //问答
	);
	//行为类型
	protected $actionType = array(
		'browse'	=>	1,
		'praise'	=>	2,
		'thank'		=>	3,
		'comment'	=>	4,
		'attention'	=>	6,
	);

	//消息类型
	protected $msgType = array(
		'sender'	=>	0,	//发送者
		'recipient'	=>	1,	//接受者
	);
	
	public function _initialize() {
		parent::_initialize();
		if(is_file('./site.inc.php')){
			$this->config = @include('./site.inc.php');
		} else {
			$common = '//站点配置信息';
			$this->config = M('SystemConfig')->getField('code,value');
			$content  = "<?php \n".$common."\nreturn ".var_export($this->config,true).";\n?>";
			file_put_contents('./site.inc.php',$content);					
		}
		if( !empty($_SESSION['user']) ) {
			$userEvent = new UserEvent();
			$this->user		=	unserialize(stripcslashes(isset($_SESSION['user']) ? $_SESSION['user'] : ''));
			$this->user_id	=	$this->user['user_id'];
			$statistic = $userEvent->userBaseStatistic( $this->user_id );
			$this->user = array_merge( $this->user, $statistic );
			$this->loginInfo = &$this->user;
		}
		$this->assign("user", $this->user);
		$this->assign("config",$this->config);
		$this->assign("login_flag", empty($this->user) ? 'false' : 'true');
	}
}
